//设置轮播图事件
var items = document.getElementsByClassName("item");
var goPrebtn = document.getElementById("goPre");
var goNextbtn = document.getElementById("goNext");
var points = document.getElementsByClassName("point");

var time = 0; //定时器变量参数
var index = 0;
// index表示第几张图片在展示 +++》第index张图片唷active这个类名
//第几个点在展示
var clearActive = function () {
    for (var i = 0; i < items.length; i++) {
        items[i].className = "item";
    };
    for (var i = 0; i < points.length; i++) {
        points[i].className = "point";
    }
}
var goIndex = function () {
    clearActive();
    items[index].className = 'item active';
    points[index].className = 'point active';
}
var goNext = function () {
    if (index < 2) {
        index++;
    } else {
        index = 0;
    };
    goIndex();
}

var goPre = function () {
    if (index == 0) {
        index = 2;
    } else {
        index--;
    };
    goIndex();
}
goNextbtn.addEventListener("click", function () {
    goNext();
    time = 0;

});
goPrebtn.addEventListener("click", function () {
    goPre();
    time = 0;
});

for (var i = 0; i < points.length; i++) {
    points[i].addEventListener("click", function () {
        var pointIndex = this.getAttribute("data-index");
        index = pointIndex;
        goIndex();
        time = 0;
    })
}

setInterval(function () {
    time++;
    if (time == 30) {
        goNext();
        time = 0;
    }
}, 100)





//设置无缝滚动字体
var content = document.getElementById("content");
var listBox = content.getElementsByTagName("ul")[0];
var dong = listBox.getElementsByTagName("li")
var speed = 1;

listBox.innerHTML += listBox.innerHTML
listBox.style.height = 11 * dong[0].offsetHeight + "px"

function run() {
    if (listBox.offsetTop < -listBox.offsetHeight / 2) {
        listBox.style.top = 0;
    } else if (listBox.offsetTop > 0) {
        listBox.style.top = -listBox.offsetHeight / 2 + "px";
    }
    listBox.style.top = listBox.offsetTop + speed + "px";
};
timer = setInterval(run, 90);
content.onmouseover = function () {
    clearInterval(timer);
}

content.onmouseout = function () {
    timer = setInterval(run, 90);
}

  // 设置日期格式
// 例子： 
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 
// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18 
Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "H+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}


var time1 = new Date().Format("HH:mm:ss");
var time2 = new Date().Format("yyyy-MM-dd HH:mm:ss");

document.getElementById("demo").innerHTML = time2;
document.getElementById("eonde").innerHTML = time1;



// 设置滚轮滑动显示隐藏
var windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
    window.onscroll = () => {
        // 页面高度
        var documentHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
        // 滚动条位置
        
        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
       console.log(scrollTop);
        var topdiv = document.getElementById("topdiv");
        if (scrollTop >= 500) {
            topdiv.style.display = "block";
        }
        if ((windowHeight + scrollTop + 2) >= documentHeight) {
            topdiv.style.display = "none";
        }
    }


    // 设置点击事件跳转滑动事件
    function aa() {
        //   window.location.hash = "#title";  
        var top = document.getElementById("duJin").offsetTop;
        ScrollTop(top, 5);
    }
    const ScrollTop = (number = 0, time) => {
        if (!time) {
            document.body.scrollTop = document.documentElement.scrollTop = number;
            return number;
        }
        const spacingTime = 10; // 设置循环的间隔时间  值越小消耗性能越高
        let spacingInex = time / spacingTime; // 计算循环的次数
        let nowTop = document.body.scrollTop + document.documentElement.scrollTop; // 获取当前滚动条位置
        let everTop = (number - nowTop) / spacingInex; // 计算每次滑动的距离
        let scrollTimer = setInterval(() => {
            if (spacingInex > 0) {
                spacingInex--;
                ScrollTop(nowTop += everTop);
            } else {
                clearInterval(scrollTimer); // 清除计时器
            }
        }, spacingTime);
    };